package com.life.controller;

import com.life.pojo.dto.TagDTO;
import com.life.pojo.vo.TagVO;
import com.life.result.Result;
import com.life.service.TagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/tag")
@Api(tags = "标签管理")
@Slf4j
public class TagController {

    @Autowired
    private TagService tagService;

    /**
     * 获取标签列表
     * @return
     */
    @GetMapping
    @ApiOperation("获取标签列表")
    public Result<List<TagVO>> getTagList() {
        List<TagVO> tagList = tagService.getTagList();
        return Result.success(tagList);
    }

    /**
     * 新增标签
     * @param name
     * @return
     */
    @PostMapping
    @ApiOperation("新增标签")
    public Result<String> insertTag(@RequestParam String name) {
        log.info("新增标签: {}", name);
        tagService.insertTag(name);
        return Result.success();
    }

    /**
     * 更新标签
     * @param tagDTO
     * @return
     */
    @PutMapping
    @ApiOperation("更新标签")
    public Result<String> updateTag(@RequestBody TagDTO tagDTO) {
        log.info("更新标签: {}", tagDTO);
        tagService.updateTag(tagDTO);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除标签")
    public Result<String> deleteTag(@PathVariable Long id) {
        log.info("删除标签: {}", id);
        tagService.deleteTag(id);
        return Result.success();
    }
}
